<%
 if(task_c.done==1); donestr = "done"; else; donestr=''; end
 if(task_c.star==1); starstr = "on"; else; starstr='off'; end
-%>

<% nb = task_c.subtasks_count %>

<% if(nb>0) -%>
  <% if(not expand) -%>
    <%= link_to_remote(image_tag('expand.gif'), :url => {:controller=>'task', :action=>'expand_task',:id=>task_c.id, :item_name=>item_name}, :update=>item_name.to_s+'_'+task_c.id.to_s) %>
  <% else -%>
    <div id="collapse_<%=item_name%>_<%=task_c.id%>" style="display:inline;">
    <%= link_to_function(image_tag('collapse.gif'),"collapse('#{task_c.id}','#{item_name}')") %>
    </div>
  <% end -%>
<% else -%>
<div style="margin-left:16px;display:inline"></div>
<% end -%>

<a href="#" onclick="star_it(<%=task_c.id%>);return false;"><img src="/images/star_<%=starstr%>_2.gif" id="st<%=task_c.id%>" title="special"></a>

<% #if task_c.task_id == 0 %>
<div class="state <%=task_c.state%>"><%=task_c.state%></div>
<% #end %>

<%= render(:partial => 'task/priority', :locals => {:p=>task_c.priority}) %>
<% if session[:selected_project] != task_c.project_id and task_c.project_id != 0 and task_c.project_id != nil%>
<b><%=task_c.project.name %></b>
<% end %>

<% if nb > 0 -%><span class="gtd_project"><% end -%>
<% if task_c.done==1 -%><span class="title_done"><% end -%>
<%= task_c.title %>
<% if task_c.done==1 -%></span><% end -%>
<% if nb > 0 -%></span>(<%=nb%>)<% end -%>


(<%=task_c.user.name %><% if task_c.created_by!=nil and task_c.created_by != task_c.user_id %> <i>from <%=task_c.creator.name %></i><%end%>)
<%= render(:partial => 'task/deadline', :locals => {:task=>task_c}) -%>
<% if(task_c.notes_count > 0) %>(<a href="#" onclick="notes(<%=task_c.id%>);return false;"><%= task_c.notes_count -%> notes</a>)<% end %>

<% if task_c.subremains and task_c.subremains > 0 %>
<div class="remains" title="total time remaining"><%= task_c.subremains %></div>
<% end %>

<div class="tags"><%=task_c.tags.map{|t| t.name }.join(", ")%></div>
<div class="done_on"><% if task_c.done_on %>done <%= time_ago_in_words(task_c.done_on) %> ago<% end %></div>

<a href="#" title="edit" onclick="edit(<%=task_c.id%>,'<%=item_name%>');return false;"><img id="e_<%=item_name%>_<%=task_c.id%>" src="/images/edit.gif"></a>
<a href="#" title="cut" onclick="cut(<%=task_c.id%>,'<%=item_name%>');return false;"><img src="/images/cut.png"></a>
<a href="#" title="paste" onclick="paste(<%=task_c.id%>,'<%=item_name%>');return false;"><img src="/images/paste.png"></a>
<% if(nb>0) -%>
<a href="#" title="display only subtasks" onclick="disp_sub(<%=task_c.id%>,'<%=item_name%>');return false;"><img id="ds<%=task_c.id%>" src="/images/disp_sub.gif"></a>
<% end -%>
<% if task_c.done==0 -%>
<a href="#" title="add a sub task" onclick="add_sub(<%=task_c.id%>,'<%=item_name%>');return false;"><img id="a_<%=item_name%>_<%=task_c.id%>" src="/images/add.png"></a>
<% end -%>

<ul id="sub_<%=item_name%>_<%=task_c.id%>">
<% if(expand) -%>
<%= render(:partial=>'task', :collection=>task_c.tasks.select{|t| t.done==0}.sort_by{|t| [t.state, t.order]}, :locals=>{:tasks=>tasks, :expand=>nil, :item_name=>item_name}) %>
<%# render(:partial=>'task', :collection=>tasks.select{|t| t.task_id==task_c.id}.sort_by{|t| [t.done, t.state, t.order]}, :locals=>{:tasks=>tasks, :expand=>nil, :item_name=>item_name}) %>
<% end -%>
</ul>

